package processor;

import org.apache.log4j.Logger;

import java.util.Enumeration;
import javax.servlet.http.*;
import org.apache.struts.action.RequestProcessor;

public class MyRequestProcessor extends RequestProcessor {
    /**
     * Logger for this class
     */
    private static final Logger LOGGER = Logger
	    .getLogger(MyRequestProcessor.class);
   
    public MyRequestProcessor() {
    }

    public boolean processPreprocess(HttpServletRequest request,
	    HttpServletResponse response) {
	LOGGER
		.debug("processPreprocess(HttpServletRequest, HttpServletResponse) - start");
	LOGGER.info("-------------- My Logging Start--------------");
	LOGGER.info("Request URI = " + request.getRequestURI());
	LOGGER.info("Context Path = " + request.getContextPath());
	Enumeration<?> headerNames = request.getHeaderNames();
	LOGGER.info("Request Header:");
	while (headerNames.hasMoreElements()) {
	    String headerName = (String) headerNames.nextElement();
	    Enumeration<?> headerValues = request.getHeaders(headerName);
	    while (headerValues.hasMoreElements()) {
		String headerValue = (String) headerValues.nextElement();
		LOGGER.info("\t" + headerName + " = " + headerValue);
	    }
	}
	LOGGER.info("Locale = " + request.getLocale());
	LOGGER.info("Method = " + request.getMethod());
	LOGGER.info("Path Info = " + request.getPathInfo());
	LOGGER.info("Protocol = " + request.getProtocol());
	LOGGER.info("Remote Address = " + request.getRemoteAddr());
	LOGGER.info("Remote Host = " + request.getRemoteHost());
	LOGGER.info("Remote User = " + request.getRemoteUser());
	LOGGER.info("Requested Session Id = " + request.getRequestedSessionId());
	LOGGER.info("Scheme = " + request.getScheme());
	LOGGER.info("Server Name = " + request.getServerName());
	LOGGER.info("Server Port = " + request.getServerPort());
	LOGGER.info("Servlet Path = " + request.getServletPath());
	LOGGER.info("Secure = " + request.isSecure());
	LOGGER.info("-------------- My Logging End  --------------");

    LOGGER
		.debug("processPreprocess(HttpServletRequest, HttpServletResponse) - end");
	return true;
    }
}
